package com.springinaction.ch05;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


/**
 * @author ssk
 * @Title: Spitter
 * @ProjectName SpringInAction
 * @Description: TODO
 * @date 18-12-9下午5:57
 */
public class Spitter {
    private Long id;
    @NotNull
    @Size(max = 10, min = 1)
    private String username;
    @NotNull
    @Size(min = 1, max = 10)
    private String password;
    private  String firstName;
    private String lastName;
    public Spitter() { }
    public Spitter(String username, String password, String firstName, String lastName) {
       this(null, username, password, firstName, lastName);
    }

    public Spitter(Long id, String username, String password, String firstName, String lastName) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, "id", "username");
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(obj, obj, "id", "username");

    }

    @Override
    public String toString() {
        return "Spitter{"
                + "id=" + id
                + ", username='" + username + '\''
                + ", password='" + password + '\''
                + ", firstName='" + firstName + '\''
                + ", lastName='" + lastName + '\''
                + '}';
    }
}
